package com.briup.cms.web.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.cms.bean.Slideshow;
import com.briup.cms.dao.SlideshowDao;
import com.briup.cms.service.ISlideshowService;
import com.briup.cms.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.runtime.regexp.joni.Config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2025-03-19
 */
@Api(tags = "轮播图模块")
@RestController
@RequestMapping("/slideshow")
@Slf4j
public class SlideshowController {
    @Autowired
    private SlideshowDao slideshowDao;

    @GetMapping("/test")
    public Result test() {
        System.out.println("in slideshow test...");

        Slideshow slideshow = slideshowDao.selectById(1);

        return Result.success(slideshow);
    }
    @Autowired
    private ISlideshowService slideshowService;

    @ApiOperation(value = "查询所有可用的轮播图")
    @GetMapping("/queryAllEnable")
    public Result queryAllEnable() {
        List<Slideshow> list = slideshowService.queryAllEnable();
        return Result.success(list);
    }
    @ApiOperation(value = "管理员条件分页查询轮播图")
    @GetMapping("/query")
    public Result query(Integer pageNum,Integer pageSize,
                        String desc,String status){
        IPage<Slideshow> p= slideshowService.queryAll(pageNum,pageSize, status, desc);
        return Result.success(p);
    }
    @ApiOperation(value = "管理员Id查询轮播图")
    @GetMapping("/queryById/{id}")
    public Result queryById(@PathVariable("id") Integer id){
        Slideshow s= slideshowService.queryById(id);
        return Result.success(s);
    }
    @ApiOperation(value = "管理员新增或修改轮播图")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Slideshow slideshow) {
        slideshowService.saveOrUpdate(slideshow);
        return Result.success("操作成功");
    }
    @ApiOperation(value = "管理员删除轮播图")
    @DeleteMapping("/deleteByBatch/{ids}")
    public Result deleteSlideshowInBatch(@PathVariable("ids") List<Integer> ids){
        log.info("ids: {}",ids);
        slideshowService.deleteInBatch(ids);
        return Result.success("删除成功");
    }
}

